from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

# 创建数据库引擎
DATABASE_URL = "mysql+pymysql://root:cwqin.521@localhost:3306/basic archives"
engine = create_engine(DATABASE_URL, echo=True, pool_size=10, max_overflow=20)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

# 创建Base类
Base = declarative_base()


# 定义一个依赖项来管理数据库会话
def get_db():
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()
